package com.lemon.smartsafetynew.ui.fragment.record;

import android.os.Bundle;

import com.lemon.android.http.LemonRequestParams;
import com.lemon.smartsafety.app.RefreshType;
import com.lemon.smartsafety.listener.RecyclerTClickListener;
import com.lemon.smartsafetynew.ui.fragment.base.BasePullToRefreshFragment;
import com.lemon.smartsafety.utils.app.UIHelper;
import com.lemon.smartsafetynew.entity.common.DateTypeEnum;
import com.lemon.smartsafetynew.entity.ledger.LedgerBuildingCheckItemVo;
import com.lemon.smartsafetynew.entity.ledger.LedgerBuildingItemVo;
import com.lemon.smartsafetynew.net.services.SafeLedgerServices;
import com.lemon.smartsafetynew.ui.activity.ledger.LedgerBuildingCheckItemDetailActivity;
import com.lemon.smartsafetynew.ui.adapter.record.RecordBuildingCheckItemListAdapter;
import com.lemon.smartsafetynew.ui.fragment.ledger.LedgerBuildingCheckItemListFragment;
import com.lemon.smartsafetynew.util.common.CommonUtil;
import com.lemon.smartsafetynew.util.constants.KeyConstants;

import java.util.List;

import kale.adapter.LemonRcvAdapter;

/**
 * @deprecated 暂时没用了 2018/2/7
 * Created by Andrew on 2017/10/21.
 */

public class PatrolCheckItemFragment extends BasePullToRefreshFragment<LedgerBuildingCheckItemVo, List<LedgerBuildingCheckItemVo>>
        implements RecyclerTClickListener<LedgerBuildingCheckItemVo> {

    private static LedgerBuildingItemVo mLedgerBuildingItemVo;

    @Override
    public void onPullRefresh() {

        LemonRequestParams params = new LemonRequestParams("");
        params.put("type", DateTypeEnum.DAY.getName().toLowerCase());
        params.put("date", CommonUtil.getNowTimeStr(DateTypeEnum.DAY));
        params.put("building_id", mLedgerBuildingItemVo.getBuilding_id());
        params.put("pageNum", currentPage);
        params.put("pageSize", pageSize);

        SafeLedgerServices
                .init()
                .getBuildingCheckItemList(RefreshType.REFRESH, params);
    }

    @Override
    public void onLoadMore() {

        LemonRequestParams params = new LemonRequestParams("");
        params.put("type", DateTypeEnum.DAY.getName().toLowerCase());
        params.put("date", CommonUtil.getNowTimeStr(DateTypeEnum.DAY));
        params.put("building_id", mLedgerBuildingItemVo.getBuilding_id());
        params.put("pageNum", currentPage);
        params.put("pageSize", pageSize);

        SafeLedgerServices
                .init()
                .getBuildingCheckItemList(RefreshType.LOAD_MORE, params);
    }

    @Override
    public boolean goRefreshOnCreate() {
        return true;
    }

    @Override
    public LemonRcvAdapter<LedgerBuildingCheckItemVo> getLemonAdapter() {
        return new RecordBuildingCheckItemListAdapter(mDataList, this);
    }

    @Override
    public String getHttpTag() {
        return KeyConstants.URL_GET_SAFE_LEDGER_BUILDING_CHECK_ITEM_LIST;
    }

    @Override
    protected void getBaseArguments() {
        super.getBaseArguments();

        Bundle bundle = getArguments();

        if (bundle != null) {
            if (bundle.containsKey(KeyConstants.KEY_LEDGER_PATROL_BUILDING_VO)) {
                mLedgerBuildingItemVo = (LedgerBuildingItemVo) bundle.getSerializable(KeyConstants.KEY_LEDGER_PATROL_BUILDING_VO);
            }
        }

    }

    public static LedgerBuildingCheckItemListFragment newInstance(LedgerBuildingItemVo mLedgerBuildingItemVo) {

        Bundle args = new Bundle();
        args.putSerializable(KeyConstants.KEY_LEDGER_PATROL_BUILDING_VO, mLedgerBuildingItemVo);

        LedgerBuildingCheckItemListFragment fragment = new LedgerBuildingCheckItemListFragment();
        fragment.setArguments(args);
        return fragment;
    }

    @Override
    public void onItemClick(LedgerBuildingCheckItemVo data, int position) {
        Bundle bundle = new Bundle();
        bundle.putSerializable(KeyConstants.KEY_LEDGER_PATROL_CHECK_ITEM_VO, data);
        bundle.putSerializable(KeyConstants.KEY_LEDGER_PATROL_BUILDING_VO, mLedgerBuildingItemVo);
        UIHelper.showActivity(getmContext(), bundle, LedgerBuildingCheckItemDetailActivity.class);
    }

}
